<!-- This sample code requires the mhash library for PHP versions older than 5.1.2
	http://hmhash.sourceforge.net/ -->
<!-- This page can be customized using standard html -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>

<title> Payment Form </title>

<?php
// load vars.php where the login and transaciton key are specified
include ("vars.php");

// Receive the posted amount and format it as a dollar amount without the currency symbol
$amount		= number_format(trim($_POST["x_amount"],"$"),2);

// Generate a random sequence number (required by SIM API)
$sequence	= rand(1, 1000);

// Generate a timestamp
$timestamp	= time ();

// The following lines generate the SIM fingerprint.  PHP versions 5.1.2 and
// newer have the necessary hmac function built in.  For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
{	$fingerprint = hash_hmac("md5", $login . "^" . $sequence . "^" . $timestamp . "^" . $amount . "^", $key); }
else 
{ $fingerprint = bin2hex(mhash(MHASH_MD5, $login . "^" . $sequence . "^" . $timestamp . "^" . $amount . "^", $key)); }
?>

</head>
<body>

Please choose an amount:

<!-- This form will post to itself to begin with -->
<form name='donateForm' method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'>

<!-- Invoice and description are specified in the vars.php file -->
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
<input type='hidden' name='x_description' value='<?php echo $description; ?>' />

<!-- In order to automatically format the amount and  generate the fingerprint
	this page will automatically post/reload every time the amount is changed -->
$<input type='text'   name='x_amount' value='<?php echo $amount; ?>' onChange='document.donateForm.submit()' />

<!-- Insert the remaining required fields -->
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timestamp; ?>' />
<input type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_login' value='<?php echo $login; ?>' />
<input type='hidden' name='x_show_form' value='PAYMENT_FORM' />

<!-- When the submit button is pressed, it will stop posting to itself and instead
	post to the URL specified in vars.php -->
<input type='submit' value='Submit' onclick="javascript: document.donateForm.action='<?php echo $URL; ?>'"/>
</form>

</body>
</html>